/**
 *
 * @author ace
 * @create 2017/7/26
 */
class ViewManager {

    private dict = {};

    find(name: string): any {
        if (!this.dict[name] && egret.hasDefinition(name)) {
            let Clazz = egret.getDefinitionByName(name);
            this.dict[name] = new Clazz();
            this.dict[name].visible = false;
        }
        return this.dict[name];
    }

    open(name: string, otherClose: boolean = true, eff: number = 1, dark: boolean = true): any {
        if (!name) return;

        let Clazz: any = egret.getDefinitionByName(name);
        if (!Clazz) {
            console.log("*********无法显示*********", name);
            return;
        }

        if (!this.dict[name]) this.dict[name] = new Clazz();

        let baseSprite: BaseSprite = this.dict[name];

        if (baseSprite) {
            if (otherClose && baseSprite.layer) {
                baseSprite.layer.removeChildren();
            }
            if (baseSprite instanceof BasePanel) {
                baseSprite.show(eff, dark);
            } else {
                baseSprite.show();
            }

        }

        return baseSprite;
    }

    close(name: string) {
        if (!this.dict[name]) return;

        let baseSprite: BaseSprite = this.dict[name];
        if (baseSprite) {
            baseSprite.hide();
        }
    }
}